<?php
ob_start();
include('connect/connect.php');
include 'class/class.phieuthu.php';	
	$phieuthu=new phieuthu();
	$giangvien = new giangvien();
check_admin();
// thinhnc 2013-04-13 edit fields
if ($_POST['khoa'] == 2) {
	$_POST['f_sobuoi'] = '';
	$_POST['f_hstart'] = '';
	$_POST['f_hend'] = '';
	$_POST['f_tkb'] = '';
	$_POST['f_ca'] = '';
	//$_POST['f_ngaybatdau'] = '';
	$_POST["f_ngayketthuc"] = '';
}

if($_POST['check_ok'] == 1 ) 
{
            $t = "UPDATE  tbl_thuphieu
            SET 				
				f_sobuoi = '".$_POST['f_sobuoi']."',
				f_giobatdau = '".$_POST['f_hstart']."',
				f_gioketthuc = '".$_POST['f_hend']."',
				f_tkb = '".$_POST['f_tkb']."',
				f_ca =  '".$_POST['f_ca']."',
				f_ngaybatdau =  '".str_replace("/","-",$_POST['f_ngaybatdau'])."',
				f_ngayketthuc = '".$_POST["f_ngayketthuc"]."',
				f_giangvien =  '".$_POST['f_giangvien']."',
				f_tengiangvien =  '".$phieuthu->giang_vien($_POST['f_giangvien'])."',
				f_tennguoitao =  '".$phieuthu->search_user($_POST['nguoitao'])."',
				f_gioitinh =  '".$_POST['gioitinh']."',
				f_mahocvien =  '".$_POST['mahocvien']."',				
            	f_ngaysinh =  '".$_POST['ngaysinh']."',
            	f_diachi =  '".$_POST['diachi']."',
            	f_phone =  '".$_POST['phone']."',
            	f_loaihinh =  '".$_POST['loaihinh']."',
            	f_khoa =  '".$_POST['khoa']."',
            	f_lop =  '".$_POST['lop']."',
            	f_hovaten =  '".$_POST['hovaten']."',            	
            	            	
            	f_sonha =  '".$_POST['dkbd_loaihinh']."',
            	f_phuong =  '".$_POST['dkbd_khoa']."',
            	f_quan =  '".$_POST['dkbd_lop']."',
            	f_tp =  '".$_POST['dkbd_ngaybatdau']."',
				f_email =  '".$_POST['dkbd_tkb']."',
            	f_dkbd_ca =  '".$_POST['dkbd_ca']."',
            	f_nguoitao =  '".$_POST['nguoitao']."',
            	f_muchp =  '".$_POST['muchp']."',
            	f_tienhp =  '".$_POST['tienhp']."',
            	f_tiengt =  '".$_POST['tiengt']."',
            	f_tiencd =  '".$_POST['tiencd']."',
            	f_miengiam =  '".$_POST['miengiam']."',
            	f_thucthu =  '".$_POST['thucthu']."',
            	f_lydo =  '".$_POST['lydo']."',
            	f_ngaytao =  '".$_POST['ngaytao']."',            	
            	f_trangthai =  '".$_POST['trangthai']."',
            	f_hoahong =  '".$_POST['hoahong']."',
                  f_nghenghiep =  '".$_POST['nghenghiep']."',
            	file =  '".$_POST['file']."'
            WHERE
            	f_maphieu ='".$_POST['f_maphieu_']."' LIMIT 1 ;";
				// thinhnc 2013-04-15
				/*
				Kiem tra thay doi giang vien:
				- Reset het lich ranh da chon truoc do cua gv (gv cu~)
				- Cap nhat lich ranh moi cho gv (gv moi')
				*/				
				$oldGiangVienId = $_POST['old_giangvienid'];
				$oldStartDate = $_POST['old_ngaybatdau'];
				$newGiangVienId = $_POST['f_giangvien'];
				$newStartDate = $_POST['f_ngaybatdau'];		
				
				$giangvien->unsetLichRanhGV($oldGiangVienId, $_POST['old_tkb'], $_POST['old_ngaybatdau'], $_POST['old_ngayketthuc'], $_POST['old_hstart'], $_POST['old_hend']);
				$giangvien->setLichRanhGV($newGiangVienId, $_POST['f_tkb'], $_POST['f_sobuoi'], $newStartDate, $_POST['f_hstart'], $_POST['f_hend']);
				// end thinhnc 2013-04-15
 	
$l = "INSERT INTO klog (mhs,author,date,content	) 
VALUES ('".$_POST['lmhv']."','".$_POST['nguoisua']."','".$_POST['ngay']."','".$change."')";
if(mysql_query($l))

;
if (mysql_query($t)) {
	echo 'Thanh cong';
	echo "<a href=print.phieuthu.php?id=".$_POST['f_maphieu_'].">In phiếu</a>";
}     
else
{
	echo 'Update khong thanh cong';
}
}
?>